<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            padding: 20px;
        }

        .register-container {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
            overflow: hidden;
            width: 100%;
            max-width: 480px;
            animation: slideUp 0.5s ease-out;
        }

        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .register-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            padding: 40px 30px;
            text-align: center;
            color: white;
        }

        .register-header h1 {
            font-size: 28px;
            font-weight: 600;
            margin-bottom: 10px;
        }

        .register-header p {
            font-size: 14px;
            opacity: 0.9;
        }

        .register-body {
            padding: 40px 30px;
        }

        .form-group {
            margin-bottom: 20px;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-size: 14px;
            font-weight: 500;
        }

        .form-group label .required {
            color: #e53e3e;
            margin-left: 2px;
        }

        .input-wrapper {
            position: relative;
        }

        .input-wrapper input {
            width: 100%;
            padding: 12px 15px 12px 45px;
            border: 2px solid #e0e0e0;
            border-radius: 10px;
            font-size: 15px;
            transition: all 0.3s ease;
            background: #f8f9fa;
        }

        .input-wrapper input:focus {
            outline: none;
            border-color: #667eea;
            background: white;
            box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
        }

        .input-wrapper .icon {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #999;
            transition: color 0.3s ease;
        }

        .input-wrapper input:focus + .icon {
            color: #667eea;
        }

        .password-toggle {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            color: #999;
            transition: color 0.3s ease;
        }

        .password-toggle:hover {
            color: #667eea;
        }

        /* 角色选择样式 */
        .role-selection {
            margin-bottom: 20px;
        }

        .role-options {
            display: flex;
            gap: 15px;
            margin-top: 10px;
        }

        .role-option {
            flex: 1;
            position: relative;
        }

        .role-option input[type="radio"] {
            position: absolute;
            opacity: 0;
            cursor: pointer;
        }

        .role-label {
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 20px 15px;
            border: 2px solid #e0e0e0;
            border-radius: 10px;
            background: #f8f9fa;
            cursor: pointer;
            transition: all 0.3s ease;
            text-align: center;
        }

        .role-option input[type="radio"]:checked + .role-label {
            border-color: #667eea;
            background: rgba(102, 126, 234, 0.1);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
        }

        .role-label:hover {
            border-color: #667eea;
            background: rgba(102, 126, 234, 0.05);
        }

        .role-icon {
            font-size: 32px;
            margin-bottom: 8px;
        }

        .role-name {
            font-weight: 600;
            color: #333;
            font-size: 16px;
        }

        .terms-agreement {
            display: flex;
            align-items: flex-start;
            gap: 8px;
            margin-bottom: 25px;
            font-size: 14px;
        }

        .terms-agreement input[type="checkbox"] {
            width: 18px;
            height: 18px;
            cursor: pointer;
            margin-top: 2px;
        }

        .terms-agreement label {
            color: #666;
            cursor: pointer;
            line-height: 1.5;
        }

        .terms-agreement a {
            color: #667eea;
            text-decoration: none;
        }

        .terms-agreement a:hover {
            text-decoration: underline;
        }

        .register-btn {
            width: 100%;
            padding: 14px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .register-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
        }

        .register-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }

        .login-link {
            text-align: center;
            margin-top: 25px;
            padding-top: 25px;
            border-top: 1px solid #e0e0e0;
            color: #666;
            font-size: 14px;
        }

        .login-link a {
            color: #667eea;
            text-decoration: none;
            font-weight: 600;
            transition: color 0.3s ease;
        }

        .login-link a:hover {
            color: #764ba2;
            text-decoration: underline;
        }

        .error-message {
            background: #fee2e2;
            border: 2px solid #ef4444;
            color: #dc2626;
            padding: 12px 15px;
            border-radius: 8px;
            margin-bottom: 20px;
            font-size: 14px;
            font-weight: 500;
        }

        .success-message {
            background: #d1fae5;
            border: 2px solid #10b981;
            color: #059669;
            padding: 12px 15px;
            border-radius: 8px;
            margin-bottom: 20px;
            font-size: 14px;
            font-weight: 500;
        }

        .input-hint {
            font-size: 12px;
            color: #999;
            margin-top: 5px;
        }

        /* 响应式设计 */
        @media (max-width: 480px) {
            .register-container {
                max-width: 100%;
            }

            .register-header {
                padding: 30px 20px;
            }

            .register-body {
                padding: 30px 20px;
            }
        }
    </style>
</head>
<body>
    <div class="register-container">
        <div class="register-header">
            <h1>创建新账户</h1>
            <p>加入我们，开始你的编程之旅</p>
        </div>

        <div class="register-body">
            <div class="error-message" th:if="${error}" th:text="${error}"></div>
            <div class="success-message" th:if="${message}" th:text="${message}"></div>

            <form id="registerForm" action="/perform_register" method="post">
                <div class="form-group">
                    <label for="username">用户名 <span class="required">*</span></label>
                    <div class="input-wrapper">
                        <input
                            type="text"
                            id="username"
                            name="username"
                            placeholder="请输入用户名（3-20个字符）"
                            required
                            minlength="3"
                            maxlength="20"
                            autocomplete="username"
                        >
                        <span class="icon">👤</span>
                    </div>
                    <div class="input-hint">用户名只能包含字母、数字和下划线</div>
                </div>

                <div class="form-group">
                    <label for="nickname">昵称</label>
                    <div class="input-wrapper">
                        <input
                            type="text"
                            id="nickname"
                            name="nickname"
                            placeholder="请输入昵称（选填）"
                            maxlength="30"
                        >
                        <span class="icon">✨</span>
                    </div>
                </div>

                <div class="form-group">
                    <label for="email">邮箱</label>
                    <div class="input-wrapper">
                        <input
                            type="email"
                            id="email"
                            name="email"
                            placeholder="请输入邮箱地址（选填）"
                            autocomplete="email"
                        >
                        <span class="icon">📧</span>
                    </div>
                </div>

                <!-- 角色选择 -->
                <div class="form-group role-selection">
                    <label>选择角色 <span class="required">*</span></label>
                    <div class="role-options">
                        <div class="role-option">
                            <input 
                                type="radio" 
                                id="roleStudent" 
                                name="role" 
                                value="2" 
                                checked
                            >
                            <label for="roleStudent" class="role-label">
                                <span class="role-icon">👨‍🎓</span>
                                <span class="role-name">我是学生</span>
                            </label>
                        </div>
                        <div class="role-option">
                            <input 
                                type="radio" 
                                id="roleTeacher" 
                                name="role" 
                                value="1"
                            >
                            <label for="roleTeacher" class="role-label">
                                <span class="role-icon">👨‍🏫</span>
                                <span class="role-name">我是教师</span>
                            </label>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label for="password">密码 <span class="required">*</span></label>
                    <div class="input-wrapper">
                        <input
                            type="password"
                            id="password"
                            name="password"
                            placeholder="请输入密码（至少6位）"
                            required
                            minlength="6"
                            autocomplete="new-password"
                        >
                        <span class="icon">🔒</span>
                        <span class="password-toggle" onclick="togglePassword('password')">👁️</span>
                    </div>
                </div>

                <div class="form-group">
                    <label for="confirmPassword">确认密码 <span class="required">*</span></label>
                    <div class="input-wrapper">
                        <input
                            type="password"
                            id="confirmPassword"
                            name="confirmPassword"
                            placeholder="请再次输入密码"
                            required
                            autocomplete="new-password"
                        >
                        <span class="icon">🔐</span>
                        <span class="password-toggle" onclick="togglePassword('confirmPassword')">👁️</span>
                    </div>
                </div>

                <div class="terms-agreement">
                    <input type="checkbox" id="terms" required>
                    <label for="terms">
                        我已阅读并同意 <a href="#" onclick="return false;">用户协议</a> 和 <a href="#" onclick="return false;">隐私政策</a>
                    </label>
                </div>

                <button type="submit" class="register-btn">
                    <span>立即注册</span>
                </button>
            </form>

            <div class="login-link">
                已有账户？<a href="/login">立即登录</a>
            </div>
        </div>
    </div>

    <script>
        // 密码显示/隐藏切换
        function togglePassword(fieldId) {
            const passwordInput = document.getElementById(fieldId);
            const toggleIcon = passwordInput.nextElementSibling.nextElementSibling;

            if (passwordInput.type === 'password') {
                passwordInput.type = 'text';
                toggleIcon.textContent = '🙈';
            } else {
                passwordInput.type = 'password';
                toggleIcon.textContent = '👁️';
            }
        }
    </script>
</body>
</html>


